package controller

import (
	"github.com/gin-gonic/gin"
	"lab.com/biz"
	"lab.com/request"
)

type cUser struct {
	APIBase
}

// User .
var User = cUser{}

// 所有用户
// Login return login (all user)
func (user *cUser) Login(c *gin.Context) {
	inputParams := request.LoginInputReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	res, err := biz.User.Login(c, inputParams)
	user.Resp(c, res, err)
}

// ContentEdit return content edit (all user)
func (user *cUser) ContentEdit(c *gin.Context) {
	inputParams := request.ContentEditReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.ContentEdit(c, inputParams)
	user.Resp(c, nil, err)
}

// InfoUpdate return user info update (all user)
func (user *cUser) InfoUpdate(c *gin.Context) {
	inputParams := request.InfoUpdateReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.InfoUpdate(c, inputParams)
	user.Resp(c, nil, err)
}

// 不校验权限，所有用户和非用户都可以查看，在首页显示
// Info return user info (all)
func (user *cUser) Info(c *gin.Context) {
	inputParams := request.UserInfoReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	res, err := biz.User.Info(c, inputParams)
	user.Resp(c, res, err)
}

// List return user list (all)
func (user *cUser) List(c *gin.Context) {
	inputParams := request.UserListReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	res, err := biz.User.List(c, inputParams)
	user.Resp(c, res, err)
}

// 管理员
// Add return user add (admin)
func (user *cUser) Add(c *gin.Context) {
	inputParams := request.UserAddReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.Add(c, inputParams)
	user.Resp(c, nil, err)
}

// ListInManage return user list in manage (admin)
func (user *cUser) ListInManage(c *gin.Context) {
	inputParams := request.ListInManageReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	res, err := biz.User.ListInManage(c, inputParams)
	user.Resp(c, res, err)
}

// EditInManage return user edit in manage (admin)
func (user *cUser) EditInManage(c *gin.Context) {
	inputParams := request.EditInManageReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.EditInManage(c, inputParams)
	user.Resp(c, nil, err)
}

// IsUse return user is use (admin)
func (user *cUser) IsUse(c *gin.Context) {
	inputParams := request.UserIsUseReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.IsUse(c, inputParams)
	user.Resp(c, nil, err)
}

// Delete return user delete (admin)
func (user *cUser) Delete(c *gin.Context) {
	inputParams := request.UserDeleteReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.Delete(c, inputParams)
	user.Resp(c, nil, err)
}

// IsManager return user is manager (admin)
func (user *cUser) IsManager(c *gin.Context) {
	inputParams := request.UserIsManagerReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.IsManager(c, inputParams)
	user.Resp(c, nil, err)
}

// PasswordReset return user password reset (admin)
func (user *cUser) PasswordReset(c *gin.Context) {
	inputParams := request.PasswordResetReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.PasswordReset(c, inputParams)
	user.Resp(c, nil, err)
}


// PasswordEdit return user password edit
func (user *cUser) PasswordEdit(c *gin.Context) {
	inputParams := request.PasswordEditReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		user.Resp(c, nil, err)
		return
	}

	err := biz.User.PasswordEdit(c, inputParams)
	user.Resp(c, nil, err)
}